FROM yiisoftware/yii2-php:7.3-apache

# install phpredis extension
ENV PHPREDIS_VERSION 4.3.0

RUN curl -L -o /tmp/redis.tar.gz https://github.com/phpredis/phpredis/archive/$PHPREDIS_VERSION.tar.gz \
    && tar xfz /tmp/redis.tar.gz \
    && rm -r /tmp/redis.tar.gz \
    && mkdir /usr/src/php/ext -p \
    && mv phpredis-$PHPREDIS_VERSION /usr/src/php/ext/redis \
    && docker-php-ext-install redis \
    && rm -rf /usr/src/php

# install php imap, pcntl extersion
RUN sed -i 's/deb.debian.org/mirrors.ustc.edu.cn/g' /etc/apt/sources.list \
    && apt update \
    && apt install -y libc-client-dev libkrb5-dev libxslt-dev \
    && apt clean \
    && rm -r /var/lib/apt/lists/* \
    && docker-php-ext-configure imap \
        --with-kerberos \
        --with-imap-ssl \
    && docker-php-ext-install imap \
    && docker-php-ext-install pcntl

# Install wkhtmltopdf required packages and poppler-utils(pdf utils)
RUN apt update \
    && apt install xvfb libxrender1 libfontconfig1 libssl-dev poppler-utils -y \
    && apt install ttf-dejavu fonts-wqy-microhei fonts-wqy-zenhei fonts-noto -y \
    && apt clean \
    && rm -r /var/lib/apt/lists/*

# Install wkhtmltopdf
RUN curl -L -o /tmp/wkhtmltox.tar.xz https://github.com/wkhtmltopdf/wkhtmltopdf/releases/download/0.12.4/wkhtmltox-0.12.4_linux-generic-amd64.tar.xz \
    && tar -xvf /tmp/wkhtmltox.tar.xz \
    && rm -r /tmp/wkhtmltox.tar.xz \
    && mv wkhtmltox/bin/wkhtmltopdf /usr/bin/wkhtmltopdf \
    && rm -rf wkhtmltox \
    && chmod 755 /usr/bin/wkhtmltopdf

# Install tideways_xhprof
ENV TIDEWAYS_XHPROF_VERSION "4.1.7"

RUN curl -L -o /tmp/tideways_xhprof.tar.gz https://github.com/tideways/php-xhprof-extension/archive/v$TIDEWAYS_XHPROF_VERSION.tar.gz \
    && tar xfz /tmp/tideways_xhprof.tar.gz \
    && rm -r /tmp/tideways_xhprof.tar.gz \
    && mkdir /usr/src/php/ext -p \
    && mv php-xhprof-extension-$TIDEWAYS_XHPROF_VERSION /usr/src/php/ext/tideways_xhprof \
    && docker-php-ext-install tideways_xhprof \
    && rm -rf /usr/src/php

#fix debain ssl bug
RUN sed -i 's#DEFAULT@SECLEVEL=2#DEFAULT@SECLEVEL=1#' /etc/ssl/openssl.cnf

# Environment settings
ENV PATH=/app:/app/apps:/app/vendor/bin:/app/apps/vendor/bin:$PATH

CMD ["php", "/usr/local/bin/workerman.php", "start"]
